﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Reflection;
using Maticsoft.Common;

namespace Web.Manage.Common
{
    public partial class UserSessionTool : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            String methodName = Request["method"];
            Type type = this.GetType();
            MethodInfo method = type.GetMethod(methodName);
            if (method == null) throw new Exception("method is null");

            try
            {
                BeforeInvoke(methodName);
                method.Invoke(this, null);
            }
            catch (Exception ex)
            {
                Hashtable result = new Hashtable();
                result["error"] = -1;
                result["message"] = ex.Message;
                result["stackTrace"] = ex.StackTrace;
                String json = JSON.Encode(result);
                Response.Clear();
                Response.Write(json);
            }
            finally
            {
                AfterInvoke(methodName);
            }
        }
        //权限管理
        protected void BeforeInvoke(String methodName)
        {
            //Hashtable user = GetUser();
            //if (user.role == "admin" && methodName == "remove") throw .      
        }
        //日志管理
        protected void AfterInvoke(String methodName)
        {

        }
        /// <summary>
        /// Response.Write出角色名称
        /// </summary>
        public void ResponseWriteRoleName()
        {
            Hashtable hashtable = (Hashtable)Session["userInfo"];
            Response.Write(hashtable["roleName"].ToString());
        }
        /// <summary>
        /// 获取登录这的角色名称
        /// </summary>
        /// <returns></returns>
        public string getRoleName()
        {
            Hashtable hashtable = (Hashtable)Session["userInfo"];
            return hashtable["roleName"].ToString();
        }
        public string getFactoryNo()
        {
            Hashtable hashtable = (Hashtable)Session["userInfo"];
            return hashtable["factoryNo"].ToString();
        }

    }
}